<?php 


require "../common/Curl.php";

/**
 *	https://open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fox6nog&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	个人签署账号API----接口顺序排列封装
 * 	使用请求签名鉴权方式
 *  下一个------------------ 机构签署账号organ.php
 */

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createByThirdPartyUserId 创建个人签署账号  手机和邮箱最好也填，全参数填写]      有用
 * @param  [type] $thirdPartyUserId [创建个人账号的唯一标识。可将个人证件号、手机号、邮箱地址等作为此账号的唯一标识。]
 * @param  [type] $name             [姓名]
 * @param  [type] $idNumber         [证件号，请传入真实的证件信息]
 * @param  [type] $mobile           [手机号码，默认空。]
 * @param  string $idType           [证件类型，默认CRED_PSN_CH_IDCARD]
 * @param  [type] $email            [邮箱地址，默认空。]
 * @return [json]                   [个人账号accountId]
 */
function createByThirdPartyUserId($thirdPartyUserId,$name,$idNumber,$mobile,$idType,$email,$appId,$secret,$url){
    $urlss = $url."/v1/accounts/createByThirdPartyUserId";
    $data = array(
        "thirdPartyUserId"=>$thirdPartyUserId,
        "name"=>$name,
        "idType"=>$idType,
        "idNumber"=>$idNumber,
        "mobile"=>$mobile,
        "email"=>$email
    );
    $res = json_encode($data);
    $header = getHeader($data,"POST","/v1/accounts/createByThirdPartyUserId",$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
$thirdPartyUserId = "2222";  //唯一标识
$name = "刘颂晶";
$idType = "CRED_PSN_CH_IDCARD";  //大陆身份证
$idNumber = "360731199907050379";
$mobile = "15179798856";
$email = "1937318982@qq.com";
$c = createByThirdPartyUserId($thirdPartyUserId,$name,$idNumber,$mobile,$idType,$email,$appId,$secret,$url);
var_dump($c);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [updateByAccountId 根据accountId修改个人签署账号 唯一标识确定，其他参数选择修改]  有用
 * @param  [type] $accountId [创建账号返回的accountId]
 * @param  [type] $name      [姓名]
 * @param  [type] $idNumber  [证件号，请传入真实的证件信息]
 * @param  [type] $mobile    [手机]
 * @param  [type] $idType    [证件类型，默认CRED_PSN_CH_IDCARD]
 * @param  [type] $email     [邮箱]
 * @param  [type] $header    [请求头]
 * @param  string $url       [请求地址]
 * @return [json]            [返回修改后账号信息]
 */
function updateByAccountId($accountId,$name,$mobile,$email,$appId,$secret,$url){
    $urlss = $url."/v1/accounts/".$accountId;
    $data = array(
        'accountId'=>$accountId,
        'mobile'=>$mobile,
        'email'=>$email,
        'name'=>$name
    );
    $head_url = "/v1/accounts/".$accountId;
    $res = json_encode($data);
    $header = getHeader($data,"PUT",$head_url,$appId,$secret);
    $result = sendHttp($method="PUT",$urlss,$header,$res);
    return $result;
}
// $accountId = "f120cf3f2a124fc88f8438d6c919b8b6";
// $name = "lsj";
// $mobile = "15179798866";
// $email = "1532423@qq.com";
// $a = updateByAccountId($accountId,$name,$mobile,$email,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [updateByThirdId 根据thirdPartyUserId修改个人签署账号 唯一标识确定，其他参数选择修改]  有用
 * @param  [type] $thirdPartyUserId [创建个人账号的唯一标识。可将个人证件号、手机号、邮箱地址等作为此账号的唯一标识。]
 * @param  [type] $name             [姓名]
 * @param  [type] $idNumber         [证件号，请传入真实的证件信息]
 * @param  [type] $mobile           [手机]
 * @param  [type] $idType           [证件类型，默认CRED_PSN_CH_IDCARD]
 * @param  [type] $email            [邮箱]
 * @param  [type] $header           [请求头]
 * @param  string $url              [请求地址]
 * @return [json]                   [返回修改后账号信息]
 */
function updateByThirdId($thirdPartyUserId,$name,$idNumber,$mobile,$idType,$email,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/updateByThirdId?thirdPartyUserId=".$thirdPartyUserId;
	$data = [
		"thirdPartyUserId"=>$thirdPartyUserId,
		"name"=>$name,
		"idType"=>$idType,
	    "idNumber"=>$idNumber,
	    "mobile"=>$mobile,
	    "email"=>$email
	];
	$head_url = "/v1/accounts/updateByThirdId?thirdPartyUserId=".$thirdPartyUserId;
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $thirdPartyUserId = "12231";
// $name = 'lsj';
// $a = updateByThirdId($thirdPartyUserId,$name,$idNumber,$mobile,$idType,$email,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * [selectAccountId 通过accountIdID查询个人信息 就是创建完个人账号返回的数据accountID]  有用
 * @param  [type] $accountId [个人签署账号ID]
 * @param  [type] $header    [请求头]
 * @param  string $url       [沙箱环境]
 * @return [json]            [个人账号信息]
 */
function selectAccountId($accountId,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/".$accountId;
	$head_url = "/v1/accounts/".$accountId;
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $accountId = "744896dd14954584b813691a6d947e82";
// $a = selectAccountId($accountId,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
 * http://localhost/lsjeqb/b2c/person.php   有用
 * [selectThirdPartyUserId 通过thirdPartyUserId查询个人信息 就是创建时的个人唯一标识thirdPartyUserId]
 * @param  [type] $thirdPartyUserId [个人唯一标识]
 * @param  [type] $header    [请求头]
 * @param  string $url       [沙箱环境]
 * @return [json]            [个人账号信息]
 */
function selectThirdPartyUserId($thirdPartyUserId,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/getByThirdId?thirdPartyUserId=".$thirdPartyUserId;
	$head_url = "/v1/accounts/getByThirdId?thirdPartyUserId=".$thirdPartyUserId;
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"GET",$head_url,$appId,$secret);
    $result = sendHttp($method="GET",$urlss,$header,$res);
    return $result;
}
// $thirdPartyUserId = "12231";
// $a = selectThirdPartyUserId($thirdPartyUserId,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------




/**
 * [deleteByAccountId 用acccountId删除个人账户]   有用  
 * @param  [type] $accountId [accountId个人账户创建时返回的]
 * @param  [type] $header    [请求头]
 * @param  string $url       [请求地址]
 * @return [json]            [返回成功或者用户不存在]
 */
function deleteByAccountId($accountId,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/".$accountId;
	$head_url = "/v1/accounts/".$accountId;
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"DELETE",$head_url,$appId,$secret);
    $result = sendHttp($method="DELETE",$urlss,$header,$res);
    return $result;
}
// $accountId = "744896dd14954584b813691a6d947e82";
// $a = deleteByAccountId($accountId,$appId,$secret,$url);
// var_dump($a);die;

/**
 * [deleteByThirdPartyUserId 根据thirdPartyUserId删除个人账号]    有用   curlData
 * @param  [type] $thirdPartyUserId [thirdPartyUserId个人唯一标识]
 * @param  [type] $header           [请求头]
 * @param  string $url              [请求地址]
 * @return [json]                   [返回成功或者用户不存在]
 */
function deleteByThirdPartyUserId($thirdPartyUserId,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/deleteByThirdId?thirdPartyUserId=".$thirdPartyUserId;
	$head_url = "/v1/accounts/deleteByThirdId?thirdPartyUserId=".$thirdPartyUserId;
	$data =[];
    $res = json_encode($data);
    $header = getHeader($data,"DELETE",$head_url,$appId,$secret);
    $result = sendHttp($method="DELETE",$urlss,$header,$res);
    return $result;
}
// $thirdPartyUserId = "15179798856";
// $a = deleteByThirdPartyUserId($thirdPartyUserId,$appId,$secret,$url);
// var_dump($a);die;

 ?>